package com.ytf.test.fifth;

/**
 * @author: YTF
 * @date: 2024/9/19 15:34
 * @version: 1.0
 * @description: 初始化顺序
 */
public class OrderOfInitialization {

    public static void main(String[] args) {
        House house = new House();
        house.f();
        /**
         * Output:
         * window(1)
         * window(2)
         * window(3)
         * house
         * window(33)
         * f()
         *
         * w3 这里证明先初始化，然后在构造器赋值 尽管这种方法视乎效率不高，但能确保初始化。
         */
    }
}
class Window{
    public Window(int marker) {
        System.out.println("window("+marker+")");
    }
}
class House{
    Window w1 =new Window(1);

    public House() {
        System.out.println("house");
        w3 =new Window(33);
    }

    Window w2 =new Window(2);
    void f(){
        System.out.println("f()");
    }
    Window w3 =new Window(3);
}
